package com.sip.stream.media;

import android.content.SharedPreferences;
import android.util.Log;

import com.blankj.utilcode.util.SPUtils;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

public class ZFYMediaStatus {
    private ZFYCameraParameters cameraParameters = new ZFYCameraParameters();

    private int audioSessionId;
    private Date beginRecordingDate;
    private boolean forceCloseWideAngleDistortion;
    private Date lastRecordingDate;
    private int mutiCaptureTime;
    private int videoSepCounter = 0;
    private long syncTime = 0;

    @SerializedName("faceRecognize")
    private boolean faceRecognize = false;

    @SerializedName("lpRecognize")
    private boolean lpRecognize = false;

    @SerializedName("qrscan")
    private boolean qrscan = false;

    @SerializedName("lastStreamHeight")
    private int lastStreamHeight = -1;

    private AtomicBoolean waitAudioNote = new AtomicBoolean();
    private AtomicBoolean audioNote = new AtomicBoolean();
    private AtomicBoolean previewing = new AtomicBoolean();
    private AtomicBoolean videoStart = new AtomicBoolean();
    private AtomicBoolean audioStart = new AtomicBoolean();
    private AtomicBoolean preRecording = new AtomicBoolean();
    private AtomicInteger important = new AtomicInteger(0);
    private AtomicBoolean delayRecording = new AtomicBoolean();
    private AtomicBoolean remoteVideoAndAudio = new AtomicBoolean();
    private AtomicBoolean remoteOnlyAudio = new AtomicBoolean();
    private AtomicBoolean isGroupintercomAudio = new AtomicBoolean();
    private AtomicBoolean isGroupintercomVideo = new AtomicBoolean();
    private AtomicBoolean isAutoVideoWhenStream = new AtomicBoolean();
    private AtomicBoolean remoteInviteVoiceTalk = new AtomicBoolean();

    public boolean isAudioNote() {
        return this.audioNote.get();
    }

    public void setAudioNote(boolean audioNote) {
        this.audioNote.set(audioNote);
    }

    public boolean isWaitAudioNote() {
        return this.waitAudioNote.get();
    }

    public void setWaitAudioNote(boolean waitAudioNote) {
        this.waitAudioNote.set(waitAudioNote);
    }

    public boolean isPreviewing() {
        return this.previewing.get();
    }

    public void setPreviewing(boolean previewing) {
        this.previewing.set(previewing);
    }

    public boolean isDelayRecording() {
        return this.delayRecording.get();
    }

    public void setDlayRecording(boolean delayRecording) {
        this.delayRecording.set(delayRecording);
    }

    public boolean isPreRecording() {
        return this.preRecording.get();
    }

    public void setPreRecording(boolean preRecording) {
        this.preRecording.set(preRecording);
    }

    public boolean isAudioStart() {
        return this.audioStart.get();
    }

    public boolean isRemoteVideoAndAudio() {
        return this.remoteVideoAndAudio.get();
    }

    public void setRemoteVideoAndAudio(boolean remoteVideoAndAudio) {
        this.remoteVideoAndAudio.set(remoteVideoAndAudio);
        if (remoteVideoAndAudio && this.beginRecordingDate == null) {
            this.beginRecordingDate = new Date();
        }
    }

    public boolean isRemoteOnlyAudio() {
        return this.remoteOnlyAudio.get();
    }

    public void setRemoteOnlyAudio(boolean remoteOnlyAudio) {
        this.remoteOnlyAudio.set(remoteOnlyAudio);
    }

    public void setAudioStart(boolean audioStart) {
        this.audioStart.set(audioStart);
        if (audioStart) {
            Date date = new Date();
            this.beginRecordingDate = date;
            this.lastRecordingDate = date;
            setReBootFLAG(true);
            return;
        }
        this.beginRecordingDate = null;
        setReBootFLAG(false);
    }

    public boolean isVideoStart() {
        return this.videoStart.get();
    }

    public void setVideoStart(boolean videoStart) {
        this.videoStart.set(videoStart);
        if (videoStart) {
            Date date = new Date();
            this.beginRecordingDate = date;
            this.lastRecordingDate = date;
            setReBootFLAG(true);
            this.videoSepCounter = 0;
            return;
        }
        this.beginRecordingDate = null;
        setReBootFLAG(false);
        setIsAutoVideoWhenStream(false);
        this.delayRecording.set(false);
        this.videoSepCounter = 0;
    }

    public long getLastRecordingTime() {
        if (this.lastRecordingDate != null) {
            long currentTimeMillis = System.currentTimeMillis() - this.lastRecordingDate.getTime();
            this.lastRecordingDate = null;
            return currentTimeMillis;
        }
        return 0L;
    }

    public int getMutiCaptureTime() {
        return this.mutiCaptureTime;
    }

    public void setMutiCaptureTime(int mutiCaptureTime) {
        this.mutiCaptureTime = mutiCaptureTime;
    }

    public void setBeginRecordingDate(Date date) {
        this.beginRecordingDate = date;
    }

    public Date getBeginRecordingDate() {
        return this.beginRecordingDate;
    }

    public boolean isImportantAndUse() {
        if (this.important.get() > 0) {
            int i = this.important.get() - 1;
            this.important.set(i);
            Log.i("Linzy", "isImportantAndUse " + i);
            return true;
        }
        return false;
    }

    public boolean isImportant() {
        return this.important.get() > 0;
    }

    public void setImportant(boolean important) {
        if (important) {
            this.important.set(Integer.MAX_VALUE);
        } else {
            this.important.set(0);
        }
    }

    public void setImportant(int important) {
        if (this.important.get() > 999) {
            return;
        }
        this.important.set(important);
    }

    public int getAudioSessionId() {
        return this.audioSessionId;
    }

    public void setAudioSessionId(int audioSessionId) {
        this.audioSessionId = audioSessionId;
    }

    public long getSyncTime() {
        return this.syncTime;
    }

    public void setSyncTime(long syncTime) {
        this.syncTime = syncTime;
    }

    private void setReBootFLAG(boolean isReboot) {
        SPUtils.getInstance().put("ZFYCheckRunable",isReboot);
    }

    public ZFYCameraParameters getCameraParameters() {
        return this.cameraParameters;
    }

    public void setCameraParameters(ZFYCameraParameters zFYCameraParameters) {
        this.cameraParameters = zFYCameraParameters;
    }

    public void setLastRecordingDate(Date date) {
        this.lastRecordingDate = date;
    }


    public boolean isGroupintercomAudio() {
        return this.isGroupintercomAudio.get();
    }

    public void setGroupintercomAudio(boolean isGroupintercomAudio) {
        this.isGroupintercomAudio.set(isGroupintercomAudio);
    }

    public boolean isGroupintercomVideo() {
        return this.isGroupintercomVideo.get();
    }

    public void setGroupintercomVideo(boolean isGroupintercomVideo) {
        this.isGroupintercomVideo.set(isGroupintercomVideo);
    }

    public boolean isWorking() {
        return isVideoStart() || isAudioStart() || isPreRecording() || isDelayRecording() || isRemoteOnlyAudio() || isRemoteVideoAndAudio() || isGroupintercomVideo() || isGroupintercomAudio();
    }

    public boolean isNeedCommuniMode() {
        return isRemoteInviteVoiceTalk();
    }

    public boolean isAutoVideoWhenStream() {
        return this.isAutoVideoWhenStream.get();
    }

    public void setIsAutoVideoWhenStream(boolean isAutoVideoWhenStream) {
        this.isAutoVideoWhenStream.set(isAutoVideoWhenStream);
    }

    public boolean isRemoteInviteVoiceTalk() {
        return this.remoteInviteVoiceTalk.get();
    }

    public void setRemoteInviteVoiceTalk(boolean remoteInviteVoiceTalk) {
        this.remoteInviteVoiceTalk.set(remoteInviteVoiceTalk);
    }

    public boolean isFaceRecognize() {
        return this.faceRecognize;
    }

    public void setFaceRecognize(boolean faceRecognize) {
        this.faceRecognize = faceRecognize;
    }

    public boolean isLpRecognize() {
        return this.lpRecognize;
    }

    public void setLpRecognize(boolean lpRecognize) {
        this.lpRecognize = lpRecognize;
    }

    public boolean isQrscan() {
        return this.qrscan;
    }

    public void setQrscan(boolean qrscan) {
        this.qrscan = qrscan;
    }

    public int getVideoSepCounter() {
        int i = this.videoSepCounter + 1;
        this.videoSepCounter = i;
        return i;
    }

    public int getLastStreamHeight() {
        return this.lastStreamHeight;
    }

    public void setLastStreamHeight(int lastStreamHeight) {
        this.lastStreamHeight = lastStreamHeight;
    }

    public boolean isForceCloseWideAngleDistortion() {
        return this.forceCloseWideAngleDistortion;
    }

    public void setForceCloseWideAngleDistortion(boolean forceCloseWideAngleDistortion) {
        this.forceCloseWideAngleDistortion = forceCloseWideAngleDistortion;
    }

    public String toString() {
        return "isVideoStart = " + isVideoStart() + " isAudioStart = " + isAudioStart() + " isPreRecording = " + isPreRecording() + " isDelayRecording = " + isDelayRecording() + " isRemoteOnlyAudio = " + isRemoteOnlyAudio() + " isRemoteVideoAndAudio = " + isRemoteVideoAndAudio() + " isGroupintercomVideo = " + isGroupintercomVideo() + " isGroupintercomAudio = " + isGroupintercomAudio();
    }
}
